<?php
class Default_Model_Report extends Zend_Db_Table{

	protected $_name = REPORT_TABLE;
	protected $_primary = 'report_id';

	private $REPORT_ID = 'report_id';
	private $COMMENT_ID = 'comment_id';

	protected $db;

	public function __construct(){
		//Goi ket noi voi Zend Db
		$this->db = Zend_Registry::get('connectDB');
	}

	protected $_messageError = null;

	public function countReport(){
		$select = $this->db->select()
		->from(REPORT_TABLE,array('COUNT(report_id) AS totalReport'));
		$result = $this->db->fetchOne($select);
		return $result;
	}

	public function listAllReport(){
		$select = $this->db->select()->from(REPORT_TABLE);
		$select->order($this->REPORT_ID.' ASC');
		$result  = $this->db->fetchAll($select);
		return $result;
	}
	
	public function listAllReportPaging(){
		$select = $this->db->select()->from(REPORT_TABLE);
		$select->order($this->REPORT_ID.' ASC');
		return $select;
	}
	
	public function getReportBycmtId($cmtId) {
		$select = $this->db->select()->from(REPORT_TABLE)->where($this->COMMENT_ID.' = ?',$cmtId);
		$result  = $this->db->fetchAll($select);
		return $result;
	}
	
	// update info
	public function updateReportInfo($arrParam = null, $reportId){
		try {
			$this->db->update(REPORT_TABLE, $arrParam, $this->REPORT_ID.' = '.$reportId);
			return true;
		} catch (Exception $e) {
			$this->_messageError = $e->getMessage();
			return false;
		}
	}
	
	// Xoa report
	public function deleteReportById($reportId){
		try {
			$this->db->delete(REPORT_TABLE,$this->REPORT_ID.' = ' . $reportId);
			return true;
		} catch (Exception $e) {
			$this->_messageError = $e->getMessage();
			return false;
		}
	}

	public function getError(){
		return $this->_messageError;
	}
}